package com.horse.cloud.framework.mybatis.sharding;

import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;

import java.util.Collection;

/**
 * @create: Created by intelliJIDEA 19.2
 * @author: Gopan
 * @e-mail: 15923508369@163.com
 * @gmdate: 27/09/2019 15:52 星期五 (dd/MM/YYYY HH:mm)
 * @sidesc:
 */
public class PreciseModuloShardingTableAlgorithm implements PreciseShardingAlgorithm<Long> {

    @Override
    public String doSharding(final Collection<String> tableNames, final PreciseShardingValue<Long> shardingValue) {
        for (String each : tableNames) {
            if (each.endsWith(shardingValue.getValue() % 2 + "")) {
                return each;
            }
        }
        throw new UnsupportedOperationException();
    }
}
